if (!jsx3.lang.Class.forName("ux.cdb.admin.queries.contract.DetailDialog")) {

jsx3.Class.defineClass(
	"ux.cdb.admin.queries.contract.DetailDialog", jsx3.gui.Dialog, [],
	function (dialog) {
		dialog.tabList = ["Contract", "Receipt", "LoanInfo", "CoLoanInfo", "BaseInfo", "Account", "School", "Career"];
		dialog.tabMode = ["Contract", "Receipt", "Loan", "Loan", "Student", "Student", "Student", "Student"];

		dialog.prototype.initialize = function(){
            var me = this;
            var createTabByJs = true;
            if(!createTabByJs) {                
                ux.megatron.Main.loadUIResourceAsync(this.get("paneDetail"), "ux.cdb.admin", 
                    "ux/cdb/admin/contract/ui/ContractTab.xml", this, this.onLoadTab);
            } else {
                setTimeout(function(){
                    var tabbedpane = new ux.megatron.gui.TabbedPane("tabbedpane", 0, 0, "100%", "100%", "");
                    me.get("paneDetail").setChild(tabbedpane, jsx3.app.Model.PERSISTNONE);
                    //tabbedpane.getContentPane().repaint();
                    me.get("paneDetail").repaint();
                    me.onLoadTab();
                }, 0);
            }
		};

        dialog.prototype.property = function(name, token) {
            return ux.megatron.Main.getServer().getDynamicProperty(name, token);
        };

        dialog.prototype.onLoadTab = function() {

            var me = this;
			var tabNames = ["Contract", "Receipt", "LoanInfo", "CoLoanInfo", "BaseInfo", "Account", "School", "Career"];
            for(var i=0; i<tabNames.length; i++) {
                tabNames[i] = {
                    id: "tab"+tabNames[i], 
                    name: this.property("@cdb@contract@Tab" + tabNames[i])
                };
            }

            this.get("tabbedpane").addTabs(tabNames, true);
			this.count = 0;
            var f = function(){
				me.count++;
				if(me.count == 8){
					me.loadContractDetail(me.detailInfo, me.hiddenReceipt);
				}
			};
            
            //load tab content
            ux.megatron.Main.loadUIResourceAsync(this.get('tabContract').getContentPane(), 
                "ux.cdb.admin", "ux/cdb/admin/contract/ui/ContractDetail.xml", this, f);
            ux.megatron.Main.loadUIResourceAsync(this.get('tabReceipt').getContentPane(),
                "ux.cdb.admin", "ux/cdb/admin/contract/ui/ReceiptDetail.xml", this, f);
            ux.megatron.Main.loadUIResourceAsync(this.get('tabLoanInfo').getContentPane(), 
                "ux.cdb.admin", "ux/cdb/admin/loan/ui/LoanManage_DebitDetailPage.xml", this, f);
            ux.megatron.Main.loadUIResourceAsync(this.get('tabCoLoanInfo').getContentPane(), 
                "ux.cdb.admin", "ux/cdb/admin/loan/ui/LoanManage_CoDebitDetailPage.xml", this, f);
            ux.megatron.Main.loadUIResourceAsync(this.get('tabBaseInfo').getContentPane(), 
                "ux.cdb.admin", "ux/cdb/admin/customer/ui/det_baseinfo.xml", this, f);
            ux.megatron.Main.loadUIResourceAsync(this.get('tabAccount').getContentPane(), 
                "ux.cdb.admin", "ux/cdb/admin/customer/ui/det_accinfo.xml", this, f);
            ux.megatron.Main.loadUIResourceAsync(this.get('tabSchool').getContentPane(), 
                "ux.cdb.admin", "ux/cdb/admin/customer/ui/det_studyinfo.xml", this, f);
            ux.megatron.Main.loadUIResourceAsync(this.get('tabCareer').getContentPane(), 
                "ux.cdb.admin", "ux/cdb/admin/customer/ui/det_careerinfo.xml", this, f);
        };
        
		dialog.prototype.loadContractDetail = function(detailIds, hiddenReceipt) {
			var details = [], i, j=0;
			for(i=0; i<dialog.tabList.length; i++) {
				if(!hiddenReceipt || dialog.tabList[i] != "Receipt") {
					jsx3.log('loadContractDetail details : ' + this.get("tab" + dialog.tabList[i]).
								getContentPane().getDescendantsOfType(ux.cdb.admin.dataautomate.GenericDetail)[0]);
					details[j] = {
						objDetail: this.get("tab" + dialog.tabList[i]).
							getContentPane().getDescendantsOfType(ux.cdb.admin.dataautomate.GenericDetail)[0], 
						mode: dialog.tabMode[i],
						id  : detailIds[dialog.tabMode[i]]
					};
					j++;
				}
			}
			this.details = details;
			this._loadContractDetailData(details, null, this);
		};
		
		dialog.prototype._loadContractDetailData = function(details, callback, scope) {
			jsx3.log('DetailDialog#_loadContractDetail details : ' + dwr.util.toDescriptiveString(details,4));
			var handler = function(obj) {
				console.log(obj);
				obj.appPayPlanList = [];
				obj.appPayPlanList.push({distributionDate: obj.distributionDate, amt: obj.amt});
				return obj;
			};

			var detail, mode;
			for(var i=0; i<details.length; i++) {
				detail = details[i].objDetail;
				if(detail) {
					mode   = ux.cdb.admin.dataautomate.GenericDetail[details[i].mode];
					detail.setDataEntityType(mode);
					detail.setDataEntityId(details[i].id);
					if(details[i].mode == "Contract" ){ detail.setProcessHandler(handler); }
					detail.refreshData();
				}
			}
		};
	});

}